<template>
  <div class="list-container">
    <!-- <el-divider>展示所有用户信息，可根据手机号操作查询</el-divider> -->
    <vab-query-form>
      <el-form
        ref="form"
        :model="queryForm.queryBean"
        :inline="true"
        @submit.native.prevent
      >
        <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.userName"
            placeholder="姓名"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.contact"
            placeholder="联系方式"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            native-type="submit"
            @click="handleQuery"
          >
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        show-overflow-tooltip
        prop="userName"
        label="姓名"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="联系方式"
        prop="contact"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="愿望"
        prop="wish"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="时间"
        prop="wishTime"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="地址"
        prop="address"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="描述"
        prop="wishDesc"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="操作" width="200">
        <template #default="{ row }">
          <el-button
            type="success"
            icon="el-icon-s-opportunity"
            @click="showDetails(row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
    <!-- <table-edit ref="edit">修改表单 </table-edit> -->
    <wish-details ref="details"></wish-details>
  </div>
</template>
<script>
  import { getWish } from '@/api/wish'
  import WishDetails from './components/WishDetails.vue'
  export default {
    name: 'List',
    components: { WishDetails },
    data() {
      return {
        imgShow: true,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {},
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    mounted() {},
    methods: {
      // handleDelete(row) {
      //   if (row.userId) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       //TODO:删除用户
      //       // const { msg } = await doDelete({ ids: row.id })
      //       this.$baseMessage('功能待开发', 'warning')
      //       this.fetchData()
      //     })
      //   } else {
      //     this.$baseMessage('未选中任何行', 'error')
      //     return false
      //   }
      // },
      showDetails(row) {
        if (row) {
          this.$refs['details'].showEdit(row)
        } else {
        }
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getWish(this.queryForm)
        const { body } = data
        this.list = body.data
        this.total = body.totalSize
        this.$baseNotify('数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
